package com.xcjw.com.Utils;

import java.text.DecimalFormat;

/**
 * @packname com.homeclient.com.Utils
 * @filename NfcUtils
 * @date on 2018/9/3 10:30
 *****/
public class NfcUtils {
      public static final DecimalFormat df = new DecimalFormat(".00");

      public NfcUtils() {
      }

      public static String byteArrayToHex(byte[] b) {
            if(b != null && b.length != 0) {
                  StringBuffer sb = new StringBuffer(b.length * 2);

                  for(int i = 0; i < b.length; ++i) {
                        String hexNumber = Integer.toHexString(255 & b[i]);
                        sb.append(hexNumber);
                  }

                  return sb.toString();
            } else {
                  return null;
            }
      }

      public static int oneByteToInt(byte b) {
            return b & 255;
      }

      public static int bytesToInt(byte[] b, int offset) {
            return (b[offset + 0] & 255) << 24 | (b[offset + 1] & 255) << 16 | (b[offset + 2] & 255) << 8 | b[offset + 3] & 255;
      }

      public static String sugarChange(int bloodsugar) {
            String s = df.format((double)bloodsugar / 18.0D);
            return s.substring(0, s.length() - 1);
      }
}